package com.tp.base;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.tp.model.sys.SysLog;
import com.tp.model.sys.SysUser;

/**
 * 基于JFinal的通用service接口BaseService
 * @author TP
 *
 */
public class BaseService {
	
	protected static final Log log = Log.getLog(BaseService.class);
	/**
	 * 用户登录，登出记录
	 * 
	 * @param user
	 * @param operType
	 */
	public void saveLog(SysUser user, String operType) {
		try {
			String tableName = user.getTable().getName();
			Integer updateId = user.getInt("update_id");
			String updateTime = user.getStr("update_time");
			String sql = "INSERT INTO `sys_log` ( `log_type`, `oper_object`, `oper_table`," //
					+ " `oper_id`, `oper_type`, `oper_remark`, `create_time`, `create_id`) " //
					+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
			Db.update(sql, SysLog.TYPE_SYSTEM, tableName, tableName, updateId, operType, "", updateTime, updateId);
		} catch (Exception e) {
			log.error("添加日志失败", e);
		}
	}

}
